<!--- Custom tag for Modal Windows - jqModal --->
<!---
WRITTEN BY: Michael Sprague, msprague@hamilton.edu
VERSION: 0.7 (beta 1)
UPDATED: 8/25/2008

USAGE: 
<cf_window name="window" REQUIRED - becomes the id of the window
		initShow="false" - Show on page load or not (optional)
		title="Window Title"  - Appears in the title bar (optional)
		width="400px"  (optional)
		height="300px" (optional)
		closable="true" - Show the close button (optional)
		resizable="true"  - Show the resize handle (optional)
		source="windowtest.cfm" - Ajax source URL (optional)
		draggable="true" - Allow user to drag the window (optional)
		modal="true"- If true, requires action to close.  Otherwise user can click outside window to close. (optional)
		pathTojQuery="/js/jQuery126-min.js" - path to the jQuery library (optional)
		pathTojqModal="/js/jqModal.js" - path to the jqModal file (optional)
		pathTojqModalCSS="/js/jqModal/jqModal.css" - path to the desired CSS file (must include images folder in same folder) (optional)
		pathTojqDnR="/js/jqDnR.js" - path to the drag and resize add-on (optional)
		pathTojqForms="/js/jqForms.js" - path to the jqForms file for Ajax forms (optional)
		>
		Non-ajax window content can go here.
</cf_window>

INTERACTION WITH MODAL WINDOW:

Show/Hide - use jqmShow() and jqmHide() functions
		$('#windowname').jqmShow();
		$('#windowname').jqmHide();
		
Ajax - 	Use _content on the window name as the return area... example:
		$('#windowname_content').load('/applications/employee/search.cfm');
		(can also use $.ajax() method)

Forms - If you are using a form within a window, you can use this javascript above the form tag to make it submit by ajax...
		<script language="javascript" type="text/javascript">
			jqAjaxForm('testform');  // use the id of the form
		</script>		
		
Title - Change the title of a window with Javascript
		$('#windowname_title').html('test');
		
--->


<cfswitch expression="#ThisTag.ExecutionMode#">
	<!--- Start tag processing --->
	<cfcase value="start">
		<cfparam name="attributes.name" default="" />
		<cfparam name="attributes.source" default="" />
		<cfparam name="attributes.title" default="" />
		<cfparam name="attributes.width" default="400px" />
		<cfparam name="attributes.height" default="300px" />
		<cfparam name="attributes.closable" default="true" />
		<cfparam name="attributes.resizable" default="true" />
		<cfparam name="attributes.draggable" default="true" />
		<cfparam name="attributes.modal" default="true" />
		<cfparam name="attributes.initShow" default="false" />
		<cfparam name="attributes.pathTojQuery" default="/js/jQuery126-min.js" />
		<cfparam name="attributes.pathTojqmodal" default="/js/jqModal.js" />
		<cfparam name="attributes.pathTojqModalCSS" default="/js/jqModal/jqModal.css" />
		<cfparam name="attributes.pathTojqDnR" default="/js/jqDnR.js" />
		<cfparam name="attributes.pathTojqForms" default="/js/jqForms.js" />
		
		<cfif attributes.name IS "">ERROR: Name is required for a cf_window.<cfabort /></cfif>
		<cfparam name="caller.jqModalIncluded" default="0" />
		<cfparam name="caller.jQueryIncluded" default="0" />
		<cfparam name="caller.aFormIncluded" default="0" />
		<!-- Import jQuery and SimpleModal source files -->
		<cfif NOT caller.jQueryIncluded>
			<script src='<cfoutput>#attributes.pathTojQuery#</cfoutput>' type='text/javascript'></script>
			<cfset caller.jQueryIncluded = 1 />
		</cfif>
		<cfif NOT caller.jqModalIncluded>
			<script src='<cfoutput>#attributes.pathTojqModal#</cfoutput>' type='text/javascript'></script>
			<script src='<cfoutput>#attributes.pathTojqDnR#</cfoutput>' type='text/javascript'></script>
			<script src='<cfoutput>#attributes.pathTojqForms#</cfoutput>' type='text/javascript'></script>
			<link href="<cfoutput>#attributes.pathTojqmodalCSS#</cfoutput>" rel="stylesheet" rev="stylesheet" />
			<cfset caller.jqModalIncluded = 1 />
		</cfif>
		
		<cfoutput>
			<script language="javascript" type="text/javascript">
				
				$().ready(function() {
					  //$('body').append($('.jqmWindow'))
					  $('###attributes.name#').jqm({
					    //trigger: '###attributes.name#Trigger',
					    overlay: 60, /* 0-100 (int) : 0 is off/transparent, 100 is opaque */
					    overlayClass: 'whiteOverlay',
					    modal: #attributes.modal#})
					    <cfif attributes.initShow>
					    .jqmShow()
						</cfif>
					    <cfif attributes.draggable>
					    .jqDrag('.jqDrag') /* make dialog draggable, assign handle to title */
					    </cfif>;
					  <cfif attributes.resizable>				  
					  $('.lowerWindow').jqResize('.jqResize');
					  </cfif>			            
					  <cfif trim(attributes.source) GT "">
					  $.ajax({
					  	type:'GET',
					  	url:'#attributes.source#',
					  	cache:false,
					  	success: function(msg) {
					  		$('###attributes.name#_content').html(msg);
					  		}
					  });
					  </cfif>
					<cfif NOT caller.aFormIncluded>
					jqAjaxForm = function(formid,options) {
							if (!options) {
								options = {target:'###attributes.name#_content'}
							}
							$('##'+formid).ajaxForm(options); 
						 };
					<cfset caller.aFormIncluded = 1 />
					</cfif>
					
					});
			</script>
			<style type="text/css">
				div.lowerWindow {
					width:#attributes.width#;
					height:#attributes.height#;
				}
			</style>
						
			<div id="#attributes.name#" class="jqmDialog">
				<cfif attributes.closable><a href="##" class="jqmdX jqmClose"></a></cfif>
				<div class="jqmdTL jqDrag"><h3 class="jqmdTC" id="#attributes.name#_title">#attributes.title#</h3></div>
				<div class="lowerWindow">
					<div class="jqmdMSG" id="#attributes.name#_content">
		</cfoutput>
	</cfcase>
	<!--- End tag processing --->
	<cfcase value="end">
					</div>			
					<cfif attributes.resizable><div class="jqHandle jqResize"></div></cfif>
				</div>
			</div>
		</cfcase>
	</cfswitch>